/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controllers;

import com.et.mvc.JspView;


/**
 *
 * @author Administrator
 */
public class LoginController extends ApplicationController{
   
    
//    public JspView create() throws Exception{
//        User user = User.createModel(User.class, "user", request.getParameterMap());
//        System.out.println(user.getName());
//        if (user.create()){
//            redirect("/User/list.do");
//            return null;
//        }
//        else{
//            return new JspView("new_","user",user);
//        }
//    }
    
   
    public JspView login() throws Exception{
       System.out.println("login");
//       response.setContentType("text/xml; charset=UTF-8");
       String userType=request.getParameter("userType");
       String userName=request.getParameter("userName");
       String userPw=request.getParameter("userPw");

      
       if(true){
    	   request.getSession().setAttribute("userType", userType);
           request.getSession().setAttribute("userName", userName);
           response.getWriter().append("success");
           StringBuffer menuContents=new StringBuffer();
           if(userType.equals("游客")){
        	   menuContents.append("<li><a target='_self' href='index.jspx'>首页</a></li>");
        	   menuContents.append("<li><a target='_self' href='search/courseList.jspx'>课程列表查询</a></li>");
        	   menuContents.append("<li><a target='_self' href='javascript:logout();'>退出</a></li>");
           }else if(userType.equals("学生")){
        	   menuContents.append("<li><a target='_self' href='index.jspx'>首页</a></li>");
        	   menuContents.append("<li><a target='_self' href='search/courseList.jspx'>课程列表查询</a></li>");
        	   menuContents.append("<li><a target='_self' href='student/courseOperation.jspx'>选课退课</a></li>");
        	   menuContents.append("<li><a target='_self' href='student/myCourse.jspx'>我的选课</a></li>");
        	   menuContents.append("<li><a target='_self' href='javascript:logout();'>退出</a></li>");
           }else if(userType.equals("教师")){
        	   menuContents.append("<li><a target='_self' href='index.jspx'>首页</a></li>");
        	   menuContents.append("<li><a target='_self' href='search/courseList.jspx'>课程列表查询</a></li>");
        	   menuContents.append("<li><a target='_self' href='teacher/courseApply.jspx'>课程申报</a></li>");
        	   menuContents.append("<li><a target='_self' href='teacher/myCourse.jspx'>我的开课</a></li>");
        	   menuContents.append("<li><a target='_self' href='javascript:logout();'>退出</a></li>");
           }else if(userType.equals("管理员")){
        	   menuContents.append("<li><a target='_self' href='index.jspx'>首页</a></li>");
        	   menuContents.append("<li><a target='_self' href='search/courseList.jspx'>课程列表查询</a></li>");
        	   menuContents.append("<li><a target='_self' href='admin/courseApplyApprove.jspx'>课程申报审核</a></li>");
        	   menuContents.append("<li><a target='_self' href='admin/courseManage.jspx'>开设课程管理</a></li>");
        	   menuContents.append("<li><a target='_self' href='admin/systemManage.jspx'>系统设置</a></li>");
        	   menuContents.append("<li><a target='_self' href='javascript:logout();'>退出</a></li>");
           }
           request.getSession().setAttribute("menus", menuContents.toString());
       }
      
       return null;
    }
    public JspView logout() throws Exception{
        System.out.println("logout");
//        response.setContentType("text/xml; charset=UTF-8");
        request.getSession().removeAttribute("userType");
        request.getSession().removeAttribute("userName");
        response.getWriter().append("success");
        return null;
     }
}
